package com.imooc.service.impl;

import com.imooc.dataobject.ProductCategory;
import com.imooc.repository.CategoryRepository;
import com.imooc.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * FileName: CategoryServiceImpl.java
 * Description: CategoryServiceImpl
 *
 * @author HuangRI(874668739 @ qq.com)
 * @version 1.0
 * @date 2020/12/16
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryRepository categoryRepository;

    @Override
    public ProductCategory findOne(Integer categoryId) {
        Optional<ProductCategory> optionalProductCategory = categoryRepository.findById(categoryId);
        return optionalProductCategory.isPresent() ? optionalProductCategory.get() : null;
    }

    @Override
    public List<ProductCategory> findAll() {
        return this.categoryRepository.findAll();
    }

    @Override
    public List<ProductCategory> findByCategoryTypeIn(List<Integer> categoryTypeList) {
        return this.categoryRepository.findByCategoryTypeIn(categoryTypeList);
    }

    @Override
    public ProductCategory save(ProductCategory productCategory) {
        return this.categoryRepository.save(productCategory);
    }
}
